using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SmartLink.Domain.ExpandEntity.Base
{
    /// <summary>
    /// 分页项
    /// </summary>
    public class Pagination
    {
        /// <summary>
        /// 是否进行分页
        /// </summary>
        public bool IsPagination { get; set; } = true;

        /// <summary>
        /// 页码
        /// </summary>
        public int PageIndex { get; private set; } = 1;

        /// <summary>
        /// 页数
        /// </summary>
        public int PageSize { get; private set; } = 1;

        /// <summary>
        /// 是否查询总条数
        /// </summary>
        public bool IsSearchTotal { get; private set; } = false;

        /// <summary>
        /// 总记录数
        /// </summary>
        public int TotalCount { get; set; }

        /// <summary>
        /// 实例化一个具有指定属性值的 Pagination
        /// </summary>
        /// <param name="isPagination"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="isSearchTotal"></param>
        public Pagination(int pageIndex = 1, int pageSize = 15, bool isSearchTotal = false)
        {
            PageIndex = pageIndex;
            PageSize = pageSize;
            IsSearchTotal = isSearchTotal;
        }

        /// <summary>
        /// 将 Pagination 转换为 MySql 的 LIMIT 语句字符串
        /// </summary>
        /// <returns>MySql 的 LIMIT 语句字符串</returns>
        public string ToLimitString()
        {
            if (this.IsPagination)
                return string.Format(" LIMIT {0},{1} ", (PageIndex - 1) * PageSize, PageSize);
            else
                return "";
        }
    }
}
